package com.share.design.prototype;

import java.util.HashMap;
import java.util.Map;

/**
 * author:caifan
 * date:2020/2/4
 */
public class ProtoTypeShape {
    public static void main(String[] args) {
        ProtoTypeManager manager = new ProtoTypeManager();
        Circle circle = (Circle) manager.getShape("Circle");
        circle.countArea();

        Square square = (Square) manager.getShape("Square");
        square.countArea();
    }
}

class ProtoTypeManager {
    private Map<String, Shape> ht = new HashMap<String, Shape>();

    public ProtoTypeManager() {
        ht.put("Circle", new Circle());
        ht.put("Square", new Square());
    }

    public void addshape(String key, Shape obj) {
        ht.put(key, obj);
    }

    public Shape getShape(String key) {
        Shape temp = ht.get(key);
        return (Shape) temp.clone();
    }
}
